package cn.kgc.ubagnet.service.protype;

import cn.kgc.ubagnet.mapper.ProtypeMapper;
import cn.kgc.ubagnet.pojo.Protype;
import cn.kgc.ubagnet.pojo.ProtypeExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProtypeServiceImpl implements ProtypeService {
    @Resource
    ProtypeMapper protypeMapper;
    @Override
    public List<Protype> selePro(Integer level, Integer parentid) {
        ProtypeExample example=new ProtypeExample();
        ProtypeExample.Criteria criteria = example.createCriteria();
        if(level!=0&parentid!=0){
        criteria.andLevelEqualTo(level);
        criteria.andParentidEqualTo(parentid);
        List<Protype> protypes = protypeMapper.selectByExample(example);
            return protypes;
        }else if(level!=0&parentid==0){
            criteria.andLevelEqualTo(level);
            List<Protype> protypes = protypeMapper.selectByExample(example);
            return protypes;
        }else if(level==0&parentid!=0){
            criteria.andParentidEqualTo(parentid);
            List<Protype> protypes = protypeMapper.selectByExample(example);
            return protypes;
        }else{
            List<Protype> protypes = protypeMapper.selectByExample(null);
            return protypes;
        }




    }

//    查询所有的二级分类
    @Override
    public List<Protype> seleProById(Integer id) {
    if(id!=0){
        ProtypeExample example=new ProtypeExample();
        ProtypeExample.Criteria criteria = example.createCriteria();
        criteria.andParentidEqualTo(id);
        List<Protype> protypes = protypeMapper.selectByExample(example);
        return protypes;
    }else{
        List<Protype> protypes = protypeMapper.selectByExample(null);
        return protypes;
    }

    }

    @Override
    public Protype seleById(Integer id) {
        return protypeMapper.selectByPrimaryKey(id);
    }

}
